<?
	include_once ("../include/conn.php");
	include_once ('config.php');


	/**************************************
	******** 新建用户 ********
	***************************************/
	// 初始化
	$unionid = $_POST['unionid'];
	$openid= $_POST['openid'];

	$results = array(
		'code'=>0,
		'openid' => $openid,
		'unionid' => $unionid,
		'msg'=>'返回数据！'
	);
	
	////////////////////////////////////得到openid和unionid后，新建用户//////////////////////////////
	$cmd_find = "select * from {$TABLE_C}user where openid = '$openid' or unionid = '$unionid'";

	// echo $mydb->num_rows($cmd_find);
	# 如果查询不到用户，就新建用户
	if($mydb->num_rows($cmd_find)==0){
		$mydb->query("insert into {$TABLE_C}user (openid,unionid,datetime) values ('$openid','$unionid',NOW())");
	}

	// ////////////////////////////////////////////返回给前端//////////////////////////////////////
	
	echo json_encode($results);

	// 结束
	mysql_close();
?>